package com.lenovo.testreport.gray.web.languageTest.controller;

import com.lenovo.testreport.general.service.GeneralReportService;
import com.lenovo.testreport.gray.web.languageTest.model.GrayWebLanguageEnglishPropertiesReport;
import com.lenovo.testreport.gray.web.languageTest.model.GrayWebLanguageTraditionalPropertiesReport;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author CJF
 * @date 2018/12
 * <p>
 * 主要对report主表进行操作，查询报告
 */
@Controller
@RequestMapping("/gray/web")
public class GrayWebReportController {
    @Autowired
    @Qualifier("GrayWebLanguageEnglishPropertiesReportService")
    private GeneralReportService grayWebLanguageEnglishPropertiesReportService;

    @Autowired
    @Qualifier("GrayWebLanguageTraditionalPropertiesReportService")
    private GeneralReportService grayWebLanguageTraditionalPropertiesReportService;

    //查找所有报告

    @RequestMapping("/language/english/properties/FindAllReport")
    public @ResponseBody
    List<GrayWebLanguageEnglishPropertiesReport> FindAllReport(HttpServletRequest request) {

        return grayWebLanguageEnglishPropertiesReportService.findAllReport(request.getParameter("tablename"));
    }

    //按时间和版本查找报告
    @RequestMapping("/language/english/properties/FindAllReportByTime")
    public @ResponseBody
    List<GrayWebLanguageEnglishPropertiesReport> FindAllReportByTime(HttpServletRequest request) {

        String version = "";
        if (request.getParameter("version") != "") {
            version = request.getParameter("version").replace("\"", "");
        }
        version += "%";
        List<GrayWebLanguageEnglishPropertiesReport> list = grayWebLanguageEnglishPropertiesReportService.findReportByTime(request.getParameter("tablename"), request.getParameter("start"), request.getParameter("end"), version);
        return list;
    }

    //按类型查找报告
    @RequestMapping("/language/english/properties/FindByType")
    public @ResponseBody
    List FindByType(HttpServletRequest request) {

        return grayWebLanguageEnglishPropertiesReportService.findByType(request.getParameter("tablename"), request.getParameter("type"));
    }

    //查找所有版本号
    @RequestMapping("/language/english/properties/FindAllVersion")
    public @ResponseBody
    List<String> FindAllVersion(HttpServletRequest request) {
        return grayWebLanguageEnglishPropertiesReportService.findAllVersion(request.getParameter("tablename"));
    }


    @RequestMapping("/language/tw/properties/FindAllReport")
    public @ResponseBody
    List tw_FindAllReport(HttpServletRequest request) {

        return grayWebLanguageTraditionalPropertiesReportService.findAllReport(request.getParameter("tablename"));
    }

    //按时间和版本查找报告
    @RequestMapping("/language/tw/properties/FindAllReportByTime")
    public @ResponseBody
    List<GrayWebLanguageTraditionalPropertiesReport> tw_FindAllReportByTime(HttpServletRequest request) {

        String version = "";
        if (request.getParameter("version") != "") {
            version = request.getParameter("version").replace("\"", "");
        }
        version += "%";
        List<GrayWebLanguageTraditionalPropertiesReport> list = grayWebLanguageTraditionalPropertiesReportService.findReportByTime(request.getParameter("tablename"), request.getParameter("start"), request.getParameter("end"), version);
        return list;
    }

    //按类型查找报告
    @RequestMapping("/language/tw/properties/FindByType")
    public @ResponseBody
    List tw_FindByType(HttpServletRequest request) {

        return grayWebLanguageTraditionalPropertiesReportService.findByType(request.getParameter("tablename"), request.getParameter("type"));
    }

    //查找所有版本号
    @RequestMapping("/language/tw/properties/FindAllVersion")
    public @ResponseBody
    List<String> tw_FindAllVersion(HttpServletRequest request) {

        return grayWebLanguageTraditionalPropertiesReportService.findAllVersion(request.getParameter("tablename"));
    }

}
